package cn.green.core.adapt.models.table;

import cn.green.core.components.setter.DeleteKey;
import cn.green.core.components.setter.PrimaryKey;
import cn.green.core.model.QFieldModel;
import cn.green.core.model.QTableModel;
import lombok.Data;
import lombok.EqualsAndHashCode;

import java.util.ArrayList;
import java.util.List;

/**
 * @author wang.yishu
 * @version 1.0
 * @className OrmTable
 * @description 表信息
 * @date 2025/5/9 16:30
 */
@EqualsAndHashCode(callSuper = true)
@Data
public class OrmTable extends QTableModel {
    //该表的版本
    protected String version;
    //该表的主键
    protected QFieldModel primary;
    //该表的删除字段
    protected QFieldModel deleted;
    //该表的父级字段
    protected QFieldModel parent;
    //主键类型
    protected PrimaryKey primaryKey;
    //删除类型
    protected DeleteKey deleteKey;

    protected Class<?> clazz;

    @Override
    public List<QFieldModel> allFields() {
        List<QFieldModel> rtn = new ArrayList<>();
        if (primary != null) {
            rtn.add(primary);
        }
        if (this.fields != null) {
            for (QFieldModel field : this.fields) {
                if (field != null) {
                    rtn.add(field);
                }
            }
        }
        if (parent != null) {
            rtn.add(parent);
        }
        if (deleted != null) {
            rtn.add(deleted);
        }
        return rtn;
    }
}
